﻿using System;
using System.Diagnostics;

namespace Mindless
{
    /// <summary>
    /// A choice is something that can be a branch in a decision tree.
    /// </summary>
    public interface IChoice
    {
    }

    /// <summary>
    /// A bid contains not just an explicit level (e.g. Pass, Two, Three, Four), but may also
    /// contain an intended (but undisclosed) lead trump card.
    /// </summary>
    public class Bid : IChoice
    {
        /// <summary>
        /// Creates a new bid at the given level with the given suit.
        /// </summary>
        public Bid(BidEnum level, Card lead)
        {
            this.level = level;
            this.lead = lead;
        }

        /// <summary>
        /// Creates a new bid at the given level.
        /// </summary>
        public Bid(BidEnum level) : this(level, null)
        {
        }

        /// <summary>
        /// Answers a textual representation of this bid. E.g. "Three in Hearts".
        /// </summary>
        public override string ToString()
        {
            return this.lead == null
                ? this.level.ToString()
                : string.Format("{0} ({1})", this.level, this.lead);
        }

        /// <summary>
        /// Member-wise equality.
        /// </summary>
        public override bool Equals(object obj)
        {
            Bid bid = (Bid) obj;

            return (bid.level == this.level) && (bid.lead == this.lead);
        }

        /// <summary>
        /// Member-wise hash.
        /// </summary>
        public override int GetHashCode()
        {
            int hash = this.level.GetHashCode();
            if (this.lead != null)
                hash += this.lead.GetHashCode();

            return hash;
        }

        /// <summary>
        /// The level of this bid.
        /// </summary>
        public BidEnum Level
        {
            get { return this.level; }
        }
        private BidEnum level;

        /// <summary>
        /// The lead card (if any) of this bid.
        /// </summary>
        public Card Lead
        {
            get { return this.lead; }
        }
        private Card lead;
    }

    /// <summary>
    /// The bids available in a game of Setback.
    /// </summary>
    public enum BidEnum { Pass = 0, Two = 2, Three = 3, Four = 4 };
}
